<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教师活动管理系统</title>
    <!-- Bootstrap -->
    <link th:href="@{/vendors/jquery/css/dataTables.min.css}" rel="stylesheet">
    <link th:href="@{/vendors/bootstrap/dist/css/bootstrap.min.css}" rel="stylesheet">
    <!-- Font Awesome -->
    <link th:href="@{/vendors/font-awesome/css/font-awesome.min.css}" rel="stylesheet">
    <!-- NProgress -->
    <link th:href="@{/vendors/nprogress/nprogress.css}" rel="stylesheet">
    <!-- iCheck -->
    <link th:href="@{/vendors/iCheck/skins/flat/green.css}" rel="stylesheet">
    <!-- Custom Theme Style -->
    <link th:href="@{/build/css/custom.min.css}" rel="stylesheet">
</head>
<style>
    .btn {
        width: 85px;
    }
</style>
<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div class="col-md-3 left_col">
            <div class="left_col scroll-view">
                <div class="navbar nav_title" style="border: 0;">
                    <a href="#" class="site_title"><span>教师活动管理系统</span></a>
                </div>
                <div class="clearfix"></div>
                <!-- menu profile quick info -->
                <div class="profile clearfix">
                    <div class="profile_pic">
                        <img th:src="@{/images/img.jpg}" alt="..." class="img-circle profile_img">
                    </div>
                    <div class="profile_info">
                        <span>欢迎,</span>
                        <h2>[[${session.cur_user.realName}]]</h2>
                    </div>
                </div>
                <!-- /menu profile quick info -->
                <br/>
                <!-- sidebar menu -->
                <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
                    <div class="menu_section">
                        <ul class="nav side-menu">
                            <li><a><i class="fa fa-desktop"></i> 基本操作 <span
                                    class="fa fa-chevron-down"></span></a>
                                <ul class="nav child_menu">
                                    <li><a href="/activity">活动信息</a></li>
                                    <li><a href="/user/info">个人信息</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
                <!-- /sidebar menu -->
            </div>
        </div>

        <!-- top navigation -->
        <div class="top_nav">
            <div class="nav_menu">
                <div class="nav toggle">
                    <a id="menu_toggle"><i class="fa fa-bars"></i></a>
                </div>
                <nav class="nav navbar-nav">
                    <ul class=" navbar-right">
                        <li class="nav-item dropdown open" style="padding-left: 15px;">
                            <a href="javascript:;" class="user-profile dropdown-toggle" aria-haspopup="true"
                               id="navbarDropdown" data-toggle="dropdown" aria-expanded="false">
                                <img th:src="@{/images/img.jpg}" alt="">[[${session.cur_user.realName}]]
                            </a>
                            <div class="dropdown-menu dropdown-usermenu pull-right" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" href="/user/info">个人信息</a>
                                <a class="dropdown-item" href="/user/logout"><i
                                        class="fa fa-sign-out pull-right"></i>退出</a>
                            </div>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
        <!-- /top navigation -->
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 ">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>个人资料</h2>
                                <ul class="nav navbar-right panel_toolbox">
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br/>
                                <div id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align"
                                               for="loginName">登录账号 </span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input th:value="${session.cur_user.loginName}" type="text" id="loginName"
                                                   class="form-control " disabled>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align"
                                               for="score">总积分 </span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input th:value="${score}" type="text" id="score" class="form-control "
                                                   disabled>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="realName"
                                               class="col-form-label col-md-3 col-sm-3 label-align">真实姓名</label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input th:value="${session.cur_user.realName}" id="realName"
                                                   class="form-control" type="text" name="middle-name">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="email"
                                               class="col-form-label col-md-3 col-sm-3 label-align">email</label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input th:value="${session.cur_user.email}" id="email" class="form-control"
                                                   type="email" name="middle-name">
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="item form-group">
                                        <div class="col-md-6 col-sm-6 offset-md-3">
                                            <button class="btn btn-success" onclick="modifyInfo()">修改</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 ">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>修改密码</h2>
                                <ul class="nav navbar-right panel_toolbox">
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br/>
                                <div id="demo-form3" data-parsley-validate class="form-horizontal form-label-left">
                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align"
                                               for="password1">密码 </span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input type="password" id="password1"
                                                   class="form-control" required>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align"
                                               for="password2">确认密码 </span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <input type="password" id="password2" class="form-control" required>
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="item form-group">
                                        <div class="col-md-6 col-sm-6 offset-md-3">
                                            <button class="btn btn-success" onclick="modifyPassword()">修改</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /page content -->
        <!-- footer content -->
        <footer>
            <div class="pull-right">
                -------------
            </div>
            <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
    </div>
</div>

<!-- jQuery -->
<script th:src="@{/vendors/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap -->
<script th:src="@{/vendors/bootstrap/dist/js/bootstrap.bundle.min.js}"></script>
<!-- FastClick -->
<script th:src="@{/vendors/fastclick/lib/fastclick.js}"></script>
<!-- NProgress -->
<script th:src="@{/vendors/nprogress/nprogress.js}"></script>
<!-- iCheck -->
<script th:src="@{/vendors/iCheck/icheck.min.js}"></script>
<!-- Datatables -->
<script th:src="@{/vendors/jszip/dist/jszip.min.js}"></script>
<script th:src="@{/vendors/pdfmake/build/pdfmake.min.js}"></script>
<script th:src="@{/vendors/pdfmake/build/vfs_fonts.js}"></script>
<!-- Custom Theme Scripts -->
<script th:src="@{/build/js/custom.min.js}"></script>
</body>
<script>

    function modifyPassword() {
        if (confirm("确认修改?")) {
            if ($("#password1").val() != $("#password2").val()) {
                alert("两次密码不一致!");
                return;
            }
            var data = {"password": $("#password1").val()};
            $.ajax({
                url: "/user/modify/password",
                type: "post",
                data: data,
                success: function (res) {
                    alert(res.message);
                    window.location.href = "/login";
                }
            })
        }

    }

    function modifyInfo() {
        if (confirm("确认修改?")) {
            var data = {"realName": $("#realName").val(), "email": $("#email").val()};
            $.ajax({
                url: "/user/modify/info",
                type: "post",
                data: data,
                success: function (res) {
                    alert(res.message);
                    location.reload();
                }
            })
        }
    }

    function submitAddActivity() {
        var activityName = $("#activityName").val(),
            content = $("#activityContent").val(),
            score = $("#activityScore").val(),
            type = $("#activityType").val(),
            activityTime = $("#activityTime").val();

        var data = JSON.stringify({
            "activityName": activityName,
            "content": content,
            "score": score,
            "type": type,
            "activityTime": activityTime
        });
        $.ajax({
            url: "/activity/add",
            type: "post",
            data: data,
            success: function (data) {
                alert(data.message);
                // var str = "<tr>" +
                //     "<th>"+activityName+"</th>" +
                //     "<th>"+content+"</th>" +
                //     "<th>"+score+"</th>" +
                //     "<th>"+type+"</th>" +
                //     "<th>"+activityTime+"</th> </tr>";
                // $("#activityTbody").append(str);
                // $("#activityName").val("");
                // $("#activityContent").val("");
                // $("#activityScore").val("");
                // $("#activityType").val(1);
                // $("#activityTime").val();
                // $("#addActivityModal").modal("hide");
                location.reload();
            }
        })
    }

    function deleteActivity(id) {
        if (confirm("确认删除?")) {
            $.ajax({
                url: "/activity/remove",
                type: "post",
                data: {"id": id},
                success: function (res) {
                    alert(res.message);
                    location.reload();
                }
            })
        }
    }

    function modifyActivityModal(data) {
        $("#activityIdM").val(data.activityId);
        $("#activityNameM").val(data.activityName);
        $("#activityContentM").val(data.content);
        $("#activityScoreM").val(data.score);
        $("#activityTypeM").val(data.type);
        $("#activityTimeM").val(data.activityTime);
        $("#modifyActivityModal").modal("show");
    }

    function modifyActivity() {
        var activityId = $("#activityIdM").val(),
            activityName = $("#activityNameM").val(),
            content = $("#activityContentM").val(),
            score = $("#activityScoreM").val(),
            type = $("#activityTypeM").val(),
            activityTime = $("#activityTimeM").val();

        var data = JSON.stringify({
            "activityId": activityId,
            "activityName": activityName,
            "content": content,
            "score": score,
            "type": type,
            "activityTime": activityTime
        });
        $.ajax({
            url: "/activity/modify",
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: data,
            success: function (data) {
                alert(data.message);
                location.reload();
            }
        })
    }

    function filterActivity() {
        window.location.href = "/activity/filter?type=" + $("#filterType").val() + "&year=" + $("#filterYear").val();
    }

</script>
</html>